*-------------------------------------------------------------------------------------------------------------*
* The Causal Effects of R&D Grants: Evidence from a Regression Discontinuity (Santoleri et al., 2020)
*-------------------------------------------------------------------------------------------------------------*

/// Tables 5: The effects on firm growth

use $data_path/DATA_ALL_FINAL.dta, clear

* compute dep vars in log levels
gen assets_post = ln(totalassets_tp1)
gen revenues_post = ln(opturnover_tp1)
gen employees_post = ln(numberofemployees_tp1)

foreach var of varlist assets_post revenues_post employees_post  {
		winsor2 `var', cuts(2 98) suff(_w)
}

* dependent var, treatment var, pre-treatment var
local dvar6 assets_post_w award assets_pre_w
local dvar7 employees_post_w award employees_pre_w
local dvar8 revenues_post_w award revenues_pre_w

* controls for polinomyal orders on both sides of the threshold
global linear    c.rank#i.award
global quadratic c.rank#i.award c.rank#c.rank#i.award

* regression loops reproducing Tables 5
est clear
forv d=6/8 {
    forv i=2/2 {
             eststo est`d'_`i'_1: qui reghdfe `dvar`d'' $linear    if phase_smei==`i', a(competition) cluster(competition)
			 eststo est`d'_`i'_2: qui reghdfe `dvar`d'' $quadratic if phase_smei==`i', a(competition) cluster(competition)
			 eststo est`d'_`i'_3: qui reghdfe `dvar`d'' i.quintile if phase_smei==`i', a(competition) cluster(competition)
			 eststo est`d'_`i'_4: qui reghdfe `dvar`d'' $linear    if phase_smei==`i' & inrange(rank,-10,10), a(competition) cluster(competition)
			 eststo est`d'_`i'_5: qui reghdfe `dvar`d'' $quadratic if phase_smei==`i' & inrange(rank,-10,10), a(competition) cluster(competition)
			 eststo est`d'_`i'_6: qui reghdfe `dvar`d'' $linear    if phase_smei==`i' & inrange(rank,-5,5), a(competition) cluster(competition)
			 eststo est`d'_`i'_7: qui reghdfe `dvar`d'' $quadratic if phase_smei==`i' & inrange(rank,-5,5), a(competition) cluster(competition)
    }
}
* display results of Table 5 in .txt format
cap erase $output/Table_5.txt $output/Table_5.tex
esttab est6_2* using $output/Table_5.txt, replace star(* 0.10 ** 0.05 *** 0.01 ) b(3) se(3) keep(award) stat(N r2 bic, fmt(0 2 2)) title(The effects on assets growth) mtitles(All All All 10 10 5 5 ) ///
coeflabels(award "Grant") indicate( "Rank x Grant=*award#c.rank" "Rank2 x Grant=*.award#c.rank#c.rank" "Rank quintiles=*.quintile" ) varwidth(25) nonotes

* display results of Table 5 in .tex format
esttab est6_2* using $output/Table_5.tex, replace star(* 0.10 ** 0.05 *** 0.01 ) b(3) se(3) stats(N   r2 bic, fmt(0 2 2) labels(N "R-squared" "BIC")) keep(award) ///
coeflabels(award "Grant") mtitles(All All All 10 10 5 5 ) prehead(\begin{table}[htbp]\centering \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \caption{The effects on assets growth} \begin{tabular}{l*{9}{c}} \toprule) ///
postfoot(\bottomrule \end{tabular}  \end{table}) posthead(\midrule) booktabs nonotes indicate( "Rank $\times$ Grant=*.award#c.rank" "Rank^{2} $\times$ Grant=*.award#c.rank#c.rank" "Rank quintiles=*.quintile"  ) varwidth(25)

* display results of Table 5 in .txt format
esttab est7_2* using $output/Table_5.txt, append star(* 0.10 ** 0.05 *** 0.01 ) b(3) se(3) keep(award) stat(N r2 bic, fmt(0 2 2)) title(The effects on employment growth) mtitles(All All All 10 10 5 5 ) ///
coeflabels(award "Grant") indicate( "Rank x Grant=*award#c.rank" "Rank2 x Grant=*.award#c.rank#c.rank" "Rank quintiles=*.quintile" ) varwidth(25) nonotes

* display results of Table 5 in .tex format
esttab est7_2* using $output/Table_5.tex, append star(* 0.10 ** 0.05 *** 0.01 ) b(3) se(3) stats(N   r2 bic, fmt(0 2 2) labels(N "R-squared" "BIC")) keep(award) ///
coeflabels(award "Grant") mtitles(All All All 10 10 5 5 ) prehead(\begin{table}[htbp]\centering \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \caption{The effects on employment growth} \begin{tabular}{l*{9}{c}} \toprule) ///
postfoot(\bottomrule \end{tabular}  \end{table}) posthead(\midrule) booktabs nonotes indicate( "Rank $\times$ Grant=*.award#c.rank" "Rank^{2} $\times$ Grant=*.award#c.rank#c.rank" "Rank quintiles=*.quintile"  ) varwidth(25)

* display results of Table 5 in .txt format
esttab est8_2* using $output/Table_5.txt, append star(* 0.10 ** 0.05 *** 0.01 ) b(3) se(3) keep(award) stat(N r2 bic, fmt(0 2 2)) title(The effects on revenues growth) mtitles(All All All 10 10 5 5 ) ///
coeflabels(award "Grant") indicate( "Rank x Grant=*award#c.rank" "Rank2 x Grant=*.award#c.rank#c.rank" "Rank quintiles=*.quintile" ) varwidth(25) nonotes

* display results of Table 5 in .tex format
esttab est8_2* using $output/Table_5.tex, append star(* 0.10 ** 0.05 *** 0.01 ) b(3) se(3) stats(N   r2 bic, fmt(0 2 2) labels(N "R-squared" "BIC")) keep(award) ///
coeflabels(award "Grant") mtitles(All All All 10 10 5 5 ) prehead(\begin{table}[htbp]\centering \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \caption{The effects on revenues growth} \begin{tabular}{l*{9}{c}} \toprule) ///
postfoot(\bottomrule \end{tabular}  \end{table}) posthead(\midrule) booktabs nonotes indicate( "Rank $\times$ Grant=*.award#c.rank" "Rank^{2} $\times$ Grant=*.award#c.rank#c.rank" "Rank quintiles=*.quintile"  ) varwidth(25)




